package swc.smu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import swc.smu.ui.R;

/**
 * Created by smu on 2016/2/2.
 */
public class MenuListAdapter extends BaseAdapter {
    Context context;
    String[] strings;
    LayoutInflater inflater;

    public MenuListAdapter(Context context, String[] strings){
        this.context = context;
        this.strings = strings;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return strings.length;
    }

    @Override
    public Object getItem(int position) {
        return strings[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_list_menu, null);
            holder.tvItem = (TextView) convertView.findViewById(R.id.list_menu_item_id);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvItem.setText(strings[position]);
        convertView.setTag(holder);
        return convertView;
    }

    class ViewHolder {
        TextView tvItem;
    }
}
